/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Dependencias.java
 *
 * Created on 14/07/2011, 09:57:16 AM
 */
package mongolo;

import Biblioteca.peliAquiladas;
import Servicios.SM;
import com.toedter.calendar.JDateChooserCellEditor;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;


public class Dependencias extends javax.swing.JFrame {

    /** Creates new form Dependencias */
    public Dependencias() {
        initComponents();
        this.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        Dependecias_jTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        Dependecias_jTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(Dependecias_jTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 773, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private boolean notYet = true;
    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
         if (notYet) {
            notYet = false;
            try {
                String[] vecString = {"Nombre del Usuario","Nombre de la pelicula","Cant de peli. total",
                "Cant de peli. Alquiladas","Fecha de alquiler","Dias Alquilada","Fecha de vuelta"};
                DefaultTableModel ColumDTM = SM.crearFilasNecesarias(vecString);                               
                Dependecias_jTable.setModel(ColumDTM);
                TableColumn jDatePicker = Dependecias_jTable.getColumnModel().getColumn(6);
                jDatePicker.setCellEditor(new JDateChooserCellEditor());

                jDatePicker = Dependecias_jTable.getColumnModel().getColumn(4);
                jDatePicker.setCellEditor(new JDateChooserCellEditor());
                
                ArrayList<peliAquiladas> LispeliAquiladas = SM.LisPeliAlquiDependencias;
                Object[] vec = new Object[7];
                for (peliAquiladas peliAquiladas : LispeliAquiladas) {
                    vec[0] = SM.ValidarNulls(peliAquiladas.nom_usua,"Error");
                    vec[1] = SM.ValidarNulls(peliAquiladas.nom_peli,"Error");
                    vec[2] = SM.ValidarNulls(peliAquiladas.cantPeliTotal,"Error");
                    vec[3] = SM.ValidarNulls(peliAquiladas.cantAlquiPelis,"Error");
                    vec[4] = SM.ValidarNulls(peliAquiladas.fechaAlqui,"Error");
                    vec[5] = SM.ValidarNulls(peliAquiladas.diasAlqui,"Error");
                    vec[6] = SM.ValidarNulls(peliAquiladas.fechaDevuelt,"Error");

                    ColumDTM.addRow(vec);
                    Dependecias_jTable.setModel(ColumDTM);
                    vec = new Object[7];
                
                }
            }
            catch(Exception ex){
                JOptionPane.showMessageDialog(null, "Ocurrio un error los datos no se pudieron cargar; la descripcion es: " + ex.getMessage());
            }
         }
    }//GEN-LAST:event_formWindowActivated


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Dependecias_jTable;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
